package com.compass.doctor.dialog

import android.view.Gravity
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.fragment.app.FragmentActivity
import com.compass.doctor.databinding.DialogPhnoeChooseBinding
import com.compass.framework.base.BaseDialog
import com.compass.framework.base.BaseDialogFragment
import com.compass.framework.ext.gone
import com.compass.framework.ext.onClick

/**
 * Description： 选择电话
 * Date:2024/7/8 14:31
 */
class ChoosePhoneDialog {
    class Builder(
        activity: FragmentActivity,
        private var mainNumber: String?,
        private var assistantNumber: String?
    ) : BaseDialogFragment.Builder<Builder>(activity) {


        private var mOnNumberChooseCall: ((String, String) -> Unit)? = null
        private val mBinding: DialogPhnoeChooseBinding =
            DialogPhnoeChooseBinding.inflate(LayoutInflater.from(activity))

        init {
            initView()
        }

        private fun initView() {
            setContentView(mBinding.root)
            setWidth(ViewGroup.LayoutParams.MATCH_PARENT)
            setHeight(ViewGroup.LayoutParams.WRAP_CONTENT)
            setAnimStyle(BaseDialog.AnimStyle.BOTTOM)
            gravity = Gravity.BOTTOM

            mainNumber?.let {
                mBinding.tvMainNumber.text = mainNumber
            } ?: kotlin.run {
                mBinding.clSexBoy.gone()
            }

            assistantNumber?.let {
                mBinding.tvAssistantNumber.text = assistantNumber
            } ?: kotlin.run {
                mBinding.clSexGirl.gone()
            }


            mBinding.clSexBoy.onClick {
                mainNumber?.let { mOnNumberChooseCall?.invoke(it, "1") }
                dismiss()
            }
            mBinding.clSexGirl.onClick {
                assistantNumber?.let { mOnNumberChooseCall?.invoke(it, "2") }
                dismiss()
            }
            mBinding.tvCancel.onClick {
                dismiss()
            }
        }

        fun setOnNumberChooseCall(onNumberChooseCall: ((String, String) -> Unit)): Builder {
            mOnNumberChooseCall = onNumberChooseCall
            return this
        }
    }


}